import { defineStore } from "pinia";
import { menu, permission } from "../api/module/user";

export const useUserStore = defineStore({
  id: "user",
  state: () => {
    return {
      token: "",
      userInfo: {},
      permissions: [],
      menus: [],
    };
  },
  actions: {
    async loadMenus() {
      const { data, code } = await menu();
      if (code == 200) {
        console.log("菜单栏");
        
        this.menus = data;
      }
    },
    async loadPermissions() {
      const { data, code } = await permission();
      if (code == 200) {
        console.log("permission");

        this.permissions = data;
      }
    },
  },
  persist: {
    storage: localStorage,
    paths: ["token", "userInfo", "permissions", "menus"],
  },
});
